//
//  Utils.m
//  app
//
//  Created by 王宇宙 on 2017/12/26.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "Utils.h"

@implementation Utils

/** Post 请求 */
+ (void)PostWithUrlStr:(NSString *)url params:(NSDictionary *)dic SuccessBlock:(SuccessBlock)successBlock FailureBlock:(FailedBlock)failureBlock {
  
  AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  manager.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"text/html",@"text/plain",nil];
  
  [manager POST:url parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    
  } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
    if (successBlock) {
      successBlock(responseObject);
    }
    
  } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    
    if (failureBlock) {
      failureBlock(error);
    }
  }
   ];
  
  
}


/** Get 请求 */
+ (void)GetWithUrlStr:(NSString *)url params:(NSDictionary *)dic SuccessBlock:(SuccessBlock)successBlock FailureBlock:(FailedBlock)failureBlock {
  
  AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
  manager.responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"text/html",@"text/plain",nil];
  
  [manager GET:url parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
    
  } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
    
    if (successBlock) {
      successBlock(responseObject);
    }
    
  } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    
    if (failureBlock) {
      failureBlock(error);
    }
  }
   
   ];
  
}


@end
